<?php
/**
 * Created by PhpStorm.
 * User: sunzexin
 * Date: 2018/1/19
 * Time: 19:59
 */

namespace App\Http\Controllers\Admin;


use App\Http\Logics\Admin\CafeLogic;
use App\Http\Traits\CafeTrait;
use App\Http\Controllers\BaseController;
class CafeController extends BaseController
{
    use CafeTrait;
    public function getCafeList()
    {
        $star = $this->star;
        $name = $this->name;
        $check_status = $this->check_status;
        $status = $this->status;
        $limit = $this->limit;
        $data = [
            'star' => $star,
            'name' => $name,
            'check_status' => $check_status,
            'status' => $status,
            'limit' => $limit
        ];
        $response = CafeLogic::getCafeList($data);
        if ($response->code){
            return $this->response($response->code, $response->message);
        }
        return $this->response($response->code, $response->message, $response->data);
    }

    public function setCafeStatus()
    {
        $cafe_id = $this->cafe_id;
        $data = [
            'cafe_id' => $cafe_id
        ];
        $response = CafeLogic::setCafeStatus($data);
        if ($response->code){
            return $this->response($response->code, $response->message);
        }
        return $this->response($response->code, $response->message, $response->data);
    }

    public function setShowLogo()
    {
        $cafe_id = $this->cafe_id;
        $data = [
            'cafe_id' => $cafe_id
        ];
        $response = CafeLogic::setShowLogo($data);
        if ($response->code){
            return $this->response($response->code, $response->message);
        }
        return $this->response($response->code, $response->message, $response->data);
    }


    public function createCafeQrcodeOnce()
    {
        $response = CafeLogic::createCafeQrcodeOnce();
        if ($response->code){
            return $this->response($response->code, $response->message);
        }
        return $this->response($response->code, $response->message, $response->data);
    }

    /**
     * 设置每日推荐
     */
    public function setEverydayRecommend()
    {
        $cafe_id = $this->cafe_id;
        $date = $this->date;
        $data = [
            'cafe_id' => $cafe_id,
            'date' => $date
        ];
        $response = CafeLogic::setEverydayRecommend($data);
        if ($response->code){
            return $this->response($response->code, $response->message);
        }
        return $this->response($response->code, $response->message, $response->data);
    }

    public function deleteEverydayRecommend()
    {
        $cafe_id = $this->cafe_id;
        $date = $this->date;
        $data = [
            'cafe_id' => $cafe_id,
            'date' => $date
        ];
        $response = CafeLogic::deleteEverydayRecommend($data);
        if ($response->code){
            return $this->response($response->code, $response->message);
        }
        return $this->response($response->code, $response->message, $response->data);
    }

    public function getEverydayRecommendList()
    {
        $data = [];
        $response = CafeLogic::getEverydayRecommendList($data);
        if ($response->code){
            return $this->response($response->code, $response->message);
        }
        return $this->response($response->code, $response->message, $response->data);
    }

    /**
     * 审核咖啡馆通过
     * @return string
     */
    public function setCafePass()
    {
        $cafe_id = $this->cafe_id;
        $data = [
            'cafe_id' => $cafe_id
        ];
        $response = CafeLogic::setCafePass($data);
        if ($response->code){
            return $this->response($response->code, $response->message);
        }
        return $this->response($response->code, $response->message, $response->data);
    }

    /**
     * 获取咖啡馆详情
     * @return string
     */
    public function getCafeDetail()
    {
        $cafe_id = $this->cafe_id;
        $data = [
            'cafe_id' => $cafe_id
        ];
        $response = CafeLogic::getCafeDetail($data);
        if ($response->code){
            return $this->response($response->code, $response->message);
        }
        return $this->response($response->code, $response->message, $response->data);
    }

    /**
     * 删除咖啡馆
     * @return string
     * @throws \Exception
     */
    public function deleteCafe()
    {
        $cafe_id = $this->cafe_id;
        $data = [
            'cafe_id' => $cafe_id
        ];
        $response = CafeLogic::deleteCafe($data);
        if ($response->code){
            return $this->response($response->code, $response->message);
        }
        return $this->response($response->code, $response->message, $response->data);
    }

    /**
     * 给咖啡馆设置默认封面
     * @return string
     */
    public function setCafeDefaultCover()
    {
        $response = CafeLogic::setCafeDefaultCover();
        if ($response->code){
            return $this->response($response->code, $response->message);
        }
        return $this->response($response->code, $response->message, $response->data);
    }

    public function changeShang()
    {
        $user_id = $this->user_id;
        $cafe_id = $this->cafe_id;
        $data = [
            'cafe_id' => $cafe_id,
            'user_id' => $user_id
        ];
        $response = CafeLogic::changeShang($data);
        if ($response->code){
            return $this->response($response->code, $response->message);
        }
        return $this->response($response->code, $response->message, $response->data);
    }
}